﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>代理商充值</title>
<link href="../js/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="../js/function.js" type="text/javascript"></script>
<script src="../js/base.js" type="text/javascript"></script>
<script src="../js/dialog.js" type="text/javascript"></script>
<script src="../js/jquery-form.js" type="text/javascript"></script>
<script src="../js/ajax-data.js" type="text/javascript"></script>
<style>
body{ background-color: White;}
.form_table td{ height:26px;}
td input {width:300px;}
.list {border-collapse: collapse;border: none;width:640px; text-align:center;}
.list td{border: solid #ccc 1px;color:Black; height:26px;}
td a{ text-decoration:none;}
</style>
</head>
<body class="mainbody">
<div class="navigation"><a href="javascript:history.go(-1);" class="back">后退</a>首页 &gt; 代理商 &gt; 代理商充值</div>
<div id="tab">
    <ul class="tab_nav">
        <li class="selected"><a href="javascript:;">基本信息</a></li>
    </ul>
    <div class="tab_con" style="display:block;">
        <table class="form_table">
            <col width="150px"><col>
            <tbody>
            <tr>
                <th>微街秀ID：</th>
                <td>
                    <input type="text" id="user_id" name="user_id" onblur="get(this)" />
                    <label>* 6位以上的数字。</label>
                </td>
            </tr>
            <tr>
                <th>用户名：</th>
                <td id="name">                    
                </td>
            </tr>
            <tr>
                <th>公司名：</th>
                <td id="sitename">                    
                </td>
            </tr>
             <tr>
                <th>到期时间：</th>
                <td id="endtime">
                </td>
            </tr>  
            <tr>
                <th>余额：</th>
                <td id="balance" style="color:Red; font-weight:bold;">
                </td>
            </tr>               
            <tr>
                <th>充值金额：</th>
                <td>
                    <input type="text" id="amount" name="amount" maxlength="8" value="0" />
                     <label>* 可以为负数，需在备注中说明。</label>
                </td>
            </tr>      
            <tr>
                <th>备 注：</th>
                <td>
                   <textarea id="remarks" name="remarks" style="height:60px; width:500px;">管理员加款</textarea>
                   <br /><label>* 备注内容代理商也能看见。</label>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
    <div class="foot_btn_box" style=" text-align:left; padding-left:150px;">
        <input type="button" value="提 交" onclick="submits()" style="width:100px;"/>
    </div>
     <table class="list">
            <tr class="th">
                <td>日期</td>
                <td>单笔金额</td>
                <td>余额</td>
                <td>类型</td>
                <td>备注</td>
            </tr>
            <tbody id="list"></tbody>
        </table>
</div>
<script>
    $(function () {
        var user_id = getUrlArgStr("user_id");
        if (user_id != "") {
            $("#user_id").val(user_id);
            $("#user_id").blur();
        }

    })

    function submits() {
        var param = {"user_id": $("#user_id").val(), "name": $("#name").text(), "amount": $("#amount").val(), "remarks": $("#remarks").val() };
        if (param.user_id == "") {
            Alert("请填写微街秀ID")
            return false;
        }
        if (param.amount == "") {
            Alert("请输入金额")
            return false;
        }
        if (isNaN(param.amount)) {
            Alert("数字必须是数字")
            return false;
        }
        if (parseInt(param.amount) > 500000) {
            Alert("金额不能超过￥ 500000 元,可以分多次充值")
            return false;
        }
        if (param.remark == "") {
            Alert("请填写备注")
            return false;
        }
        $.post("../ajax/agent.ashx?pay", param, function (data) {
            if (data.code == 0) {
                var balance = $("#balance").html();
                if (balance != "")
                    $("#balance").html(parseFloat(balance) + parseFloat(param.amount))
                Alert("充值成功");
            }
            else
                Alert(data.msg);
        }, "json");
    }

    var oldId = "";
    function get(obj) {
        if (obj.value == "") return;
        if (oldId == obj.value) return;
        $("#name").html("");
        $("#list").html("");
        $("#sitename").html("");
        $("#linkman").html("");
        $("#endtime").html("");
        $("#balance").html("");
        $.get("../ajax/agent.ashx?get", {"user_id": obj.value }, function (data) {
            oldId = obj.value;
            if (data.code != 0)
                Alert(data.msg);
            else {
                if (data.item == null) {
                    Alert("代理商不存在")
                    return;
                }
                $("#name").html(data.item.name);
                $("#sitename").html(data.item.sitename);
                $("#linkman").html(data.item.linkman);
                $("#endtime").html(data.item.endtime.replace("T", " "));
                $("#balance").html(data.item.balance);

                GetList(1);
            }
        }, "json");
    }

    //获取代理商的金额消费记录
    function GetList(page) {
        var param = "agentid=" + $("#user_id").val() + "&page=" + page;
        AjaxStart("../ajax/agent.ashx?getlist_recoad", param, function (data) {
            if (data.code != 0) {
                $("#list").html(html + "<tr><td colspan='8'>" + data.msg + "</td></tr>");
            }
            else {
                $("#list").html("");
                var list = data.item.table;
                if (list.length == 0)
                    $("#list").append("<td colspan='5' style='height:60px;'>没有记录</td>");
                for (var i in list) {
                    var d = "";
                    if (list[i].direction == 1)
                        d = "收入"
                    else if (list[i].direction == 2)
                        d = "支出";
                    $("#list").append("<tr id = " + list[i].id + "><td>" + list[i].addtime.replace("T", " ") + "</td>" +
                    "<td>" + (list[i].direction == 2 ? (list[i].amount * -1) : list[i].amount) + "</td>" +
                    "<td>" + list[i].balance + "</td>" +
                    "<td class='col4'>" + d + "</td>" +
                    "<td>" + list[i].remarks + "</td></tr>");
                }
            }
        });
    }
</script>
</body>
</html>
